﻿#ifndef TCPCLIENTFRM_H
#define TCPCLIENTFRM_H

#include <QWidget>

#include <net/netreading.h>
#include <net/tcpsession.h>

class TcpClientTest;
namespace Ui {
class TcpClientFrm;
}
namespace QNET_NAMESPACE {
class TcpSession;
class TcpClient;
}
using namespace QNET_NAMESPACE;

/**
 * @brief The TcpClientFrm class tcp客户端测试。
 */
class TcpClientFrm : public QWidget,
        public NetReading,
        public ISessionListener
{
    Q_OBJECT

public:
    explicit TcpClientFrm(QWidget *parent = nullptr);
    ~TcpClientFrm() override;

    // ISessionListener interface
public:
    void onStateChanged(QtSocket::TcpSession *session, bool connected) override;
    void onError(QAbstractSocket::SocketError error) override;

    // NetReading interface
public:
    void onProc(const QByteArray &arry) override;
private slots:
    void on_btnConnect_clicked();

    void on_btnStop_clicked();

    void on_checkBoxReconnect_stateChanged(int arg1);

    void on_btnClear_clicked();
    void on_btnSendData_clicked();

    void on_btnClearSendData_clicked();
    void fulfil_slot(QSharedPointer<QtSocket::NetWriting> owner, int size);

private:
    void setStopEnable(bool enabled);
    /**
     * @brief logAppend  打印日志。
     * @param msg
     */
    void logAppend(QString msg);
private:
    QtSocket::TcpClient *m_client;
    QtSocket::TcpSession *m_session;
    Ui::TcpClientFrm *ui;

};

#endif // TCPCLIENTFRM_H
